Read files in a directory

The following example opens a text file for reading.

C# .NET

public static String DoTest()
{
         string strRet = "";
         string path = @"c:\temp\MyTestOpenText.txt";

         // Delete the file if it exists.
         if (!File.Exists(path))
         {
                  // Create the file.
                  FileStream fs = File.Create(path);
                  Byte[] info = new UTF8Encoding(true).GetBytes("This is some text in the file to test File.OpenText method.");
                  // Add some information to the file.
                  fs.Write(info, 0, info.Length);
                  fs.Close();
         }

         // Open the stream and read it back.
         StreamReader sr = File.OpenText(path);
         string s = "";
         while ((s = sr.ReadLine()) != null)
         {
                  strRet += (s + Environment.NewLine);
         }
         sr.Close();

         return strRet;         
}

 

Blaze++ .NET

static String DoTest()
{
         String strRet = "";
         String path = "c:\\temp\\MyTestOpenText.txt";

         // Delete the file if it exists.
         if (!File::Exists(path))
         {
                  // Create the file.
                  FileStream fs1 = File::Create(path);
                  byteA info = UTF8Encoding(true).GetBytes("This is some text in the file to test File.OpenText method.");
                  // Add some information to the file.
                  fs1.Write(info, 0, info.Length);
                  fs1.Close();
         }
         // Open the stream and read it back.
         StreamReader sr = File::OpenText(path);
         String s = "";
         while ((s = sr.ReadLine()) != null)
         {
                  strRet += (s + Environment::NewLine);
         }
         sr.Close();
         return strRet;         
}